/* File Name : ClassUtils.java */

package com.chenwenxuan.sync.event;

/**
 * This class returns a <code>String</code> object with the name of the class that is passed
 * to it.&ensp;It can return the fully-qulified class name with the package it belongs to, just the
 * package name without the class name or just the class name without the package name.
 * 
 * @author Adapted by Jose Heitor from Real Gagnon with thanks to L. Janovszki
 * @version 1.0
 */
public class ClassUtils {
  private ClassUtils() {}
  
  /**
   * Returns the class name (without the package name - if any).
   * 
   * @param c The <code>Class</code> object to be inspected.
   * @return A <code>String</code> representation of the class name (without the package prefix).
   */
  public static String getClassName(Class c) {
    String FQClassName = c.getName();
    int firstChar;
    firstChar = FQClassName.lastIndexOf ('.') + 1;
    if ( firstChar > 0 ) {
      FQClassName = FQClassName.substring ( firstChar );
      }
    return FQClassName;
    }


  /**
   * Returns the fully-qualified class name (including the package name - if any).
   * 
   * @param c The <code>Class</code> object to be inspected.
   * @return A <code>String</code> representation of the class name (with the package prefix).
   */
  // returns package and class name
  public static String getFullClassName(Class c) {
    return  c.getName();
    }

  /**
   * Returns the package name (without the class name).
   * 
   * @param c The <code>Class</code> object to be inspected.
   * @return A <code>String</code> representation of the package name (without the class name).
   * Returns an empty <code>String</code> object if the class does not belong to any package.
   */
  public static String getPackageName(Class c) {
    String fullyQualifiedName = c.getName();
    int lastDot = fullyQualifiedName.lastIndexOf ('.');
    if (lastDot==-1){ return ""; }
    return fullyQualifiedName.substring (0, lastDot);
   }
}   
